<template>
	<sw-common-frame :loading="loading">
		<template slot="button">
			<el-button type="primary" size="small" @click="handleOpenDialog()" title="新增库按钮" class="el-icon-plus"></el-button>
		</template>
		<el-form slot="query" size="small" inline>
			<el-form-item>
				<el-input placeholder="请输入按钮名称" v-model="queryData.name" clearable></el-input>
			</el-form-item>
			<el-form-item>
				<sw-dict-select v-model="queryData.type" dict-name="DISK_ROLE_BUTTON_TYPE" clearable placeholder="按钮类别" style="width: 120px"></sw-dict-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" @click="queryTableData()">搜索</el-button>
			</el-form-item>
		</el-form>
		<template slot="table">
			<el-table size="medium" :data="tableData" stripe height="100%">
				<el-table-column prop="name" label="名称" min-width="200"></el-table-column>
				<el-table-column label="类别" min-width="100" :formatter="returnButtonType"></el-table-column>
				<el-table-column prop="content" label="描述" min-width="160"></el-table-column>
				<el-table-column prop="createName" label="创建人" min-width="100"></el-table-column>
				<el-table-column prop="createTime" label="创建时间" min-width="160"></el-table-column>
				<el-table-column label="操作" width="90">
					<template slot-scope="{ row }">
						<el-button size="medium" type="text" @click="handleOpenDialog(row)">编辑</el-button>
						<el-button size="medium" type="text" @click="handleDeleteData(row)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
		</template>
		<template slot="page">
			<sw-pagination :total="dataCount" :page.sync="queryData.page" :limit.sync="queryData.limit" @change="queryTableData()"></sw-pagination>
		</template>
		<form-dialog v-model="formDialog" :data-id="dataId" @refresh="queryTableData()"></form-dialog>
	</sw-common-frame>
</template>

<script>
import { mapGetters } from 'vuex';
import formDialog from './form';
import systemMixins from '@/views/common/systemMixins';
import { getLibraryButtonList, deleteLibraryButton } from '@/api/platform/tbRoleButton';
export default {
	mixins: [systemMixins],
	components: { formDialog },
	data() {
		return {};
	},
	computed: { ...mapGetters(['dictEnums']) },
	methods: {
		//获取库按钮数据
		async getTableData() {
			let params = { ...this.queryData };
			let result = await getLibraryButtonList(params).then((res) => res.data);
			if (result.code === '0') {
				this.dataCount = parseInt(result.count);
				this.tableData = result.data || [];
			}
		},

		//删除库按钮数据
		handleDeleteData(data) {
			this.handleDeleteFunction(data.id, data.name, '库按钮');
		},

		//删除数据请求
		async deleteDataRequest(params) {
			let result = await deleteLibraryButton(params).then((res) => res.data);
			if (result.code === '0') {
				this.$message.success('删除库按钮成功');
				this.queryTableData();
			}
		},

		//格式化按钮类型
		returnButtonType(data) {
			let info = this.dictEnums['DISK_ROLE_BUTTON_TYPE'].find((item) => item.value === data.type);
			return !info ? '--' : info.msg;
		}
	}
};
</script>
<style lang="scss" scoped></style>
